package test1.truetest1;

import java.util.Random;

public class Role {
    private String name;
    private int blood;
    private char gender;
    private String face;
    String[] boyface = {"风流俊雅", "气宇轩昂", "相貌英俊", "五官端正", "相貌平平", "一塌糊涂", "面目狰狞"};
    String[] girlface = {"美轮美奂", "沉鱼落雁", "亭亭玉立", "身材较好", "相貌平平", "相貌简陋", "惨不忍睹"};

    public Role() {
    }

    public Role(String name, int blood, char gender) {
        this.name = name;
        this.blood = blood;
        this.gender = gender;
        setFace(gender);
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public String getFace() {
        return face;
    }

    public void setFace(char gender) {
        Random r = new Random();
        if (gender == '男') {
            int index = r.nextInt(boyface.length);
            this.face = boyface[index];
        } else if (gender == '女') {
            int index = r.nextInt(girlface.length);
            this.face = girlface[index];
        } else {
            this.face = "面目狰狞";
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    //定义方法用于攻击
    public void attack(Role role) {
        Random r = new Random();
        int hurt = r.nextInt(20) + 1;
        //三元变量法:a<b?c:d    若a<b,则结果为c否则为d；
        int remainBlood = role.getBlood() - hurt;
        remainBlood = remainBlood < 0 ? 0 : remainBlood;
        //修改血量；
        role.setBlood(remainBlood);
        System.out.println(this.getName() + "举起拳头，打了" + role.getName() + "一下，造成了" + hurt + "伤害，还剩" + remainBlood + "血量");
    }

    public void showRoleInfo() {
        System.out.println("姓名为:" + getName());
        System.out.println("长相为:" + getFace());
        System.out.println("血量为:" + getBlood());
        System.out.println("性别为:" + getGender());

    }
}
